package com.by.product.controller;

import com.by.product.api.service.IProductService;
import com.by.product.api.vo.ProductVo;
import com.by.rpc.annotation.ApiEndpoint;
import com.by.rpc.annotation.RpcMethod;
import com.by.rpc.annotation.RpcPath;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * 产品RPC控制器
 * 专门用于处理来自网关的RPC调用，只暴露查询接口
 */
@Service
@ApiEndpoint(serviceName = "product-service", version = "1.0.0", group = "default")
public class ProductRpcController {

    @Autowired
    @Qualifier("productServiceImpl")
    private IProductService productService;

    @RpcMethod(value = "/product/{id}", method = "GET")
    public ProductVo getProductById(@RpcPath("id") Long id) {
        return productService.getProductById(id);
    }

    @RpcMethod(value = "/product/seckill/{id}", method = "GET")
    public String decreaseStock(@RpcPath("orderId") Long orderId) {
        productService.decreaseStock(orderId);
        return "success";
    }
}
